package com.aglhz.nature.view;

import java.util.List;

import com.aglhz.base.BaseActivity;
import com.aglhz.nature.R;
import com.aglhz.nature.adapter.SecondClassificationAdapter;
import com.aglhz.nature.adapter.SecondHomeREAdapter;
import com.aglhz.nature.modle.item.ShopListData;
import com.aglhz.nature.presenter.SecondClassificationPresenter;
import com.aglhz.nature.presenter.SecondHomeREPresenter;
import com.aglhz.nature.view.iv.SecondRETitleView;
import com.jingchen.pulltorefresh.MyListener;
import com.jingchen.pulltorefresh.PullToRefreshLayout;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.ListView;

public class SecondHomeREActivity extends BaseActivity implements SecondRETitleView{
	private SecondHomeREPresenter presenter;
	private SecondHomeREAdapter adapter;
	private String tagId;	
	private String traceId;	
	ListView listView;
	private LinearLayout error_bg;
	private PullToRefreshLayout ptrl;
	private boolean isFirstIn = true;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.second_recommend);
		setActionBarTitle("商品列表");
		listView=(ListView) findViewById(R.id.second_classification_listview);
		ptrl = ((PullToRefreshLayout) findViewById(R.id.refresh_view));
		ptrl.setOnRefreshListener(new MyListener());
		error_bg=(LinearLayout) findViewById(R.id.error_bg);
		Intent intent =getIntent();
		tagId = intent.getStringExtra("homeRE1");
		traceId= intent.getStringExtra("homeRE2");
		presenter = new SecondHomeREPresenter(this);
		// basePresenter register
		presenter.register();
		presenter.loadData();
	
	}
	
	@Override
	public void onWindowFocusChanged(boolean hasFocus)
	{
		super.onWindowFocusChanged(hasFocus);
		// 第一次进入自动刷新
		if (isFirstIn)
		{
//			ptrl.autoRefresh();
			isFirstIn = false;
		}
	}
	
	
	@Override
	public void onDestroy() {
		super.onDestroy();
		// basePresenter unregister
		presenter.unregister();
	}
	
	
	
	
	
	
	@Override
	public String setTagId() {
	
		return tagId;
	}




	@Override
	public void setAdapeter(List<ShopListData> data) {
		adapter = new SecondHomeREAdapter(data, SecondHomeREActivity.this );
		listView.setAdapter(adapter);
		
	}

	@Override
	public void showErrorView() {
		listView.setVisibility(View.GONE);
		error_bg.setVisibility(View.VISIBLE);
		
	}

}
